package com.tjsinfo.tjsoa.documentationflow.dangweifawen.action;

import java.io.FileInputStream;
import java.io.FileOutputStream;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tjsinfo.tjsoa.common.ToolKit;
import com.tjsinfo.tjsoa.documentationflow.dangweifawen.bo.ITDangweifawenNeirongBO;

public class MiWenNiGaoFromAction extends Action{
	private ITDangweifawenNeirongBO dangweifawenNeirongBO;
	
	
	public ITDangweifawenNeirongBO getDangweifawenNeirongBO() {
		return dangweifawenNeirongBO;
	}


	public void setDangweifawenNeirongBO(
			ITDangweifawenNeirongBO dangweifawenNeirongBO) {
		this.dangweifawenNeirongBO = dangweifawenNeirongBO;
	}


	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		String rodomerstr = ToolKit.getRodomer();
		String numbertype = ToolKit.getProperties("com/tjsinfo/tjsoa/documentationflow/dangweifawen/properties/systemResource_zh_CN.properties", this).
		getProperty("dangweifawen.numbertype");
		Integer number  = dangweifawenNeirongBO.selectDangweifawenMaxNumber(numbertype);
		request.setAttribute("number", number);
		try { 
			 String path =  super.getServlet().getServletContext().getRealPath("/");
			  FileInputStream   fis   =   new   FileInputStream(path+"documentationflow\\dangweifawen\\docs\\" +"temp.doc");   
		          FileOutputStream   fos   =   new   FileOutputStream(path+"documentationflow\\dangweifawen\\docs\\" + rodomerstr+".doc");   
		          byte[]   buf   =   new   byte[1024];   
		          int   i   =   0;   
		          while   (   (i   =   fis.read(buf))   !=   -1)   {   
		              fos.write(buf,   0,   i);   
		          }   
		          fis.close();   
		          fos.close();
		     }  
		     catch  (Exception  e)  {  
		           
		         e.printStackTrace();  
		     }
		request.setAttribute("rodomerstr", rodomerstr);  
		return mapping.findForward("ok");
	}
	
}
